package com.qupai.lib_base.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.qupai.lib_base.utils.GlideLoadPictureUtils;


/**
 * @author (ws)
 * @datetime 2020-10-22 GMT+8
 * @detail :
 */
public class SuperImageView extends androidx.appcompat.widget.AppCompatImageView {

    private Object normalPath;
    private Object pressedPath;
    private boolean enable = true;

    public SuperImageView(@NonNull Context context) {
        super(context);
    }

    public SuperImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public SuperImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (enable) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    GlideLoadPictureUtils.loadPicture(pressedPath, this);
                    Log.i("TAG", "onTouchEvent:ACTION_DOWN ");
                    break;
                case MotionEvent.ACTION_UP:
                    GlideLoadPictureUtils.loadPicture(normalPath, this);
                    Log.i("TAG", "onTouchEvent: ACTION_UP");
                    this.performClick();
                    break;
                default:
                    break;
            }
            return true;
        } else {
            return false;
        }
    }

    public void setClickImage(Object normalPath, Object pressPath) {
        this.normalPath = normalPath;
        this.pressedPath = pressPath;
        GlideLoadPictureUtils.loadPicture(normalPath, this);
    }

    public void setTouchEnable(boolean enable) {
        this.enable = enable;
    }
}
